package com.yystudy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yystudy.model.system.SysOperLog;
import com.yystudy.model.vo.SysOperLogQueryVo;
import com.yystudy.system.mapper.SysOperLogMapper;
import com.yystudy.system.service.OperLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OperLogServiceImpl implements OperLogService {

    @Autowired
    private SysOperLogMapper sysOperLogMapper;


    /**
     * 插入数据到数据库中
     * @param sysOperLog
     */
    @Override
    public void saveSysLog(SysOperLog sysOperLog) {
        sysOperLogMapper.insert(sysOperLog);
    }


    /**
     * 条件分页查询
     * @param page
     * @param limie
     * @param sysOperLogQueryVo
     * @return
     */
    @Override
    public IPage<SysOperLog> selectPage(Long page, Long limie, SysOperLogQueryVo sysOperLogQueryVo) {
        Page<SysOperLog> pageParam = new Page<>(page, limie);

        LambdaQueryWrapper<SysOperLog> lqw = new LambdaQueryWrapper<>();
        String title = sysOperLogQueryVo.getTitle();
        String operName = sysOperLogQueryVo.getOperName();
        String createTimeBegin = sysOperLogQueryVo.getCreateTimeBegin();
        String createTimeEnd = sysOperLogQueryVo.getCreateTimeEnd();


        if (!StringUtils.isEmpty(title)){
            lqw.like(SysOperLog::getTitle,title);
        }
        if (!StringUtils.isEmpty(operName)){
            lqw.like(SysOperLog::getOperName,operName);
        }
        if (!StringUtils.isEmpty(createTimeBegin)){
            lqw.ge(SysOperLog::getCreateTime,createTimeBegin);
        }
        if (!StringUtils.isEmpty(createTimeEnd)){
            lqw.le(SysOperLog::getCreateTime,createTimeEnd);
        }
        lqw.orderByDesc(SysOperLog::getCreateTime);

        IPage<SysOperLog> sysOperLogPage = sysOperLogMapper.selectPage(pageParam, lqw);

        return sysOperLogPage;
    }


}
